// https:vueuse.org  尤老板参与的hooks
import {onMounted} from 'vue'

type Options = {
    el:string
}

export default function (options:Options):Promise<{baseUrl:string}>{

    const Base64 = (el:HTMLImageElement)=>{
        const canvas = document.createElement('canvas')
        const ctx = canvas.getContext('2d')
        canvas.width = el.width
        canvas.height = el.height
        ctx?.drawImage(el,0,0,canvas.width,canvas.height)
        return canvas.toDataURL('image/jpeg')
    }
    return new Promise((resolve)=>{
        // onMounted(()=>{
            let img:HTMLImageElement = document.querySelector(options.el) as HTMLImageElement
            // console.log(img,"=========================")
            // img.onload = ()=>{
                resolve({
                    baseUrl:Base64(img)
                })
            // }
        // })
    
        
    })
    
}
